var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/functionalComponent/fullPage/index.tsx
var fullPage_exports = {};
__export(fullPage_exports, {
  FullPage: () => FullPage
});
module.exports = __toCommonJS(fullPage_exports);
var import_icons = require("@ant-design/icons");
var import_react = __toESM(require("react"));
var import_react_dom = __toESM(require("react-dom"));
var import_util = require("../../util");
var import_index = require("./index.less");
var fullStyleInBody = {
  position: "fixed",
  width: "100%",
  height: "100%",
  top: 0,
  bottom: 0,
  left: 0,
  right: 0
};
function InnerPage({
  children,
  className,
  iconStyle = {},
  style = {},
  showIcon = true,
  residentIcon = false,
  innerStyle = {},
  getIconContainer,
  getFullContainer,
  zIndex = 99,
  onFullScreen
}, ref) {
  const el = (0, import_react.useRef)();
  const [isFullPage, setIsFullPage] = (0, import_react.useState)(false);
  const _innerStyle = { width: "100%", height: "100%", ...innerStyle };
  const [fullStyle, setFullStyle] = (0, import_react.useState)({});
  const fullHandle = (newIsFullPage) => {
    var _a, _b;
    if (newIsFullPage) {
      const { top, left, right, bottom } = ((_b = (_a = el.current) == null ? void 0 : _a.getBoundingClientRect) == null ? void 0 : _b.call(_a)) || {};
      if (top !== void 0) {
        const mw = document.documentElement.clientWidth;
        const mh = document.documentElement.clientHeight;
        el.current.parentStyle = {
          width: el.current.parentElement.offsetWidth,
          height: el.current.parentElement.offsetHeight
        };
        el.current.parentElement.style.width = el.current.parentStyle.width + "px";
        el.current.parentElement.style.height = el.current.parentStyle.height + "px";
        el.current.style.position = "fixed";
        el.current.style.top = top + "px";
        el.current.style.left = left + "px";
        el.current.style.right = mw - right + "px";
        el.current.style.bottom = mh - bottom + "px";
        el.current.style.width = "auto";
        el.current.style.height = "auto";
        setTimeout(() => {
          setIsFullPage(true);
        });
        return;
      }
    }
    el.current.style.width = import_util.iup.isNumber(_innerStyle.width) ? _innerStyle.width + "px" : _innerStyle.width;
    el.current.style.height = import_util.iup.isNumber(_innerStyle.height) ? _innerStyle.height + "px" : _innerStyle.height;
    setIsFullPage(newIsFullPage);
  };
  (0, import_util.useUpdateEffect)(() => {
    var _a, _b;
    if (isFullPage) {
      const escEvent = (e) => {
        if (e.keyCode === 27) {
          setIsFullPage(false);
        }
      };
      let newStyle = fullStyleInBody;
      let io;
      let container = getFullContainer == null ? void 0 : getFullContainer();
      if (!container) {
        const name = (_b = (_a = import_util.iup.external).getQianKun) == null ? void 0 : _b.call(_a).name;
        container = name ? document.body.querySelector(`div[data-qiankun="${name}"]`) : null;
      }
      if (container) {
        el.current.targetContainer = container;
        el.current.lastDisplay = el.current.style.display;
        const domRect = container.getBoundingClientRect();
        const mw = document.documentElement.clientWidth;
        const mh = document.documentElement.clientHeight;
        newStyle = {
          ...fullStyleInBody,
          left: domRect.left,
          top: domRect.top,
          right: mw - domRect.right,
          bottom: mh - domRect.bottom
        };
        if (window.IntersectionObserver) {
          let io2 = new IntersectionObserver(
            (entries) => {
              if (el.current) {
                if (entries[0].isIntersecting) {
                  el.current.style.display = el.current.lastDisplay;
                } else {
                  el.current.style.display = "none";
                }
              }
            },
            {
              root: el.current.targetContainer.parentElement,
              threshold: [0, 1]
            }
          );
          io2.observe(el.current.targetContainer);
        }
      } else {
        el.current.targetContainer = document.body;
      }
      el.current.lastOverFlow = el.current.targetContainer.style.overflow;
      el.current.targetContainer.style.overflow = "hidden";
      document.addEventListener("keydown", escEvent);
      setFullStyle(newStyle);
      return () => {
        document.removeEventListener("keydown", escEvent);
        if (io) {
          io.disconnect();
          io = null;
        }
      };
    } else {
      el.current.targetContainer.style.overflow = el.current.lastOverFlow;
    }
    onFullScreen == null ? void 0 : onFullScreen(isFullPage);
  }, [isFullPage]);
  (0, import_react.useImperativeHandle)(ref, () => ({
    setFullPage: fullHandle
  }));
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className,
      style: isFullPage ? { ...style, ...el.current.parentStyle } : { display: "inline-block", width: "100%", ...style }
    },
    /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: import_util.iup.classNames("iup-full-page", { "resident-icon": showIcon && (residentIcon || isFullPage) }),
        ref: el,
        style: isFullPage ? { zIndex, ..._innerStyle, ...fullStyle } : _innerStyle
      },
      /* @__PURE__ */ import_react.default.createElement(
        Icon,
        {
          getIconContainer,
          showIcon,
          onClick: () => fullHandle(!isFullPage),
          iconStyle,
          isFullPage
        }
      ),
      children
    )
  );
}
function Icon({ getIconContainer, showIcon, onClick, isFullPage, iconStyle }) {
  const [mounted, setMounted] = (0, import_react.useState)(false);
  (0, import_react.useEffect)(() => {
    setMounted(true);
  }, []);
  const targetEl = (0, import_react.useMemo)(() => {
    const iconContaner = import_util.iup.isFunction(getIconContainer) ? getIconContainer() : null;
    if (iconContaner && !iconContaner.style.position) {
      iconContaner.style.position = "relative";
    }
    return iconContaner;
  }, [mounted]);
  if (mounted) {
    const getChildren = (style) => {
      return showIcon && /* @__PURE__ */ import_react.default.createElement(
        "span",
        {
          title: isFullPage ? "退出全屏" : "全屏",
          onClick,
          className: "btn-icon",
          style: { fontSize: 18, lineHeight: 0, ...style, ...iconStyle },
          children: isFullPage ? /* @__PURE__ */ import_react.default.createElement(import_icons.FullscreenExitOutlined, null) : /* @__PURE__ */ import_react.default.createElement(import_icons.FullscreenOutlined, null)
        }
      );
    };
    return targetEl ? import_react_dom.default.createPortal(getChildren({ top: "50%", right: 5, transform: "translateY(-50%)" }), targetEl) : getChildren({ top: 12, right: 12 });
  }
  return null;
}
var FullPage = import_react.default.forwardRef(InnerPage);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  FullPage
});
